import type { GeoApiResponse, Weather15ApiResponse, Hour24, WeatherApiResponse } from '@renderer/types/axios'
import axios, { AxiosResponse } from 'axios'
import useConfig from '@renderer/store/config'

const configStore = useConfig()

// 获取和风天气格式的城市信息
export async function getGeoApi(code: number | string) {
    const key = configStore.config.weather.key
    // const url = configStore.config.weather.url
    const res: AxiosResponse<GeoApiResponse, any> = await axios.get(`https://geoapi.qweather.com/v2/city/lookup?key=${key}&location=${code}`)
    return res
}

//通过位置获取实时天气信息
export async function getWeatherApi(location: string) {
    const key = configStore.config.weather.key
    const url = configStore.config.weather.url
    return await axios.get<any, AxiosResponse<WeatherApiResponse>>(`${url}/v7/weather/now?key=${key}&location=${location}`)
}

// 获取7天天气信息
export async function getWeather7Api(location: string) {
    const key = configStore.config.weather.key
    const url = configStore.config.weather.url
    return await axios.get<any, AxiosResponse<Weather15ApiResponse>>(`${url}/v7/weather/7d?key=${key}&location=${location}`)
}

// 获取24小时天气信息
export async function getWeather24Api(location: string) {
    const key = configStore.config.weather.key
    const url = configStore.config.weather.url
    return await axios.get<any, AxiosResponse<Hour24>>(`${url}/v7/weather/24h?key=${key}&location=${location}`)
}